package
{
	public class ProjAABB_Tile
	{
		public static var Proj_AABBTile:Object;

		public static function initialize():void
		{
			Proj_AABBTile = new Object();
			Proj_AABBTile[TileMapCell.CTYPE_FULL] = ProjAABB_Full;
			Proj_AABBTile[TileMapCell.CTYPE_45DEG] = ProjAABB_45Deg;
			Proj_AABBTile[TileMapCell.CTYPE_CONCAVE] = ProjAABB_Concave;
			Proj_AABBTile[TileMapCell.CTYPE_CONVEX] = ProjAABB_Convex;
			Proj_AABBTile[TileMapCell.CTYPE_22DEGs] = ProjAABB_22DegS;
			Proj_AABBTile[TileMapCell.CTYPE_22DEGb] = ProjAABB_22DegB;
			Proj_AABBTile[TileMapCell.CTYPE_67DEGs] = ProjAABB_67DegS;
			Proj_AABBTile[TileMapCell.CTYPE_67DEGb] = ProjAABB_67DegB;
			Proj_AABBTile[TileMapCell.CTYPE_HALF] = ProjAABB_Half;
		}

		public static function ResolveBoxTile(x, y, box, t):Boolean
		{
			var _local1 = t;
			if (0 < _local1.ID)
			{
				return(Proj_AABBTile[_local1.CTYPE](x, y, box, _local1));
			}
			return(false);
			return(_local1);
		}

		private static function ProjAABB_Full(x, y, obj, t):int
		{
			var _local1 = y;
			var _local2 = x;
			var _local3 = Math.sqrt((_local2 * _local2) + (_local1 * _local1));
			obj.ReportCollisionVsWorld(_local2, _local1, _local2 / _local3, _local1 / _local3, t);
			return(CollisionType.COL_AXIS);
			return(_local3);
		}

		private static function ProjAABB_Half(x, y, obj, t):int
		{
			var _local1 = t;
			var _local3 = _local1.signx;
			var _local2 = _local1.signy;
			var ox = ((obj.pos.x - (_local3 * obj.xw)) - _local1.pos.x);
			var oy = ((obj.pos.y - (_local2 * obj.yw)) - _local1.pos.y);
			var dp = ((ox * _local3) + (oy * _local2));
			if (dp < 0)
			{
				_local3 = _local3 * (-dp);
				_local2 = _local2 * (-dp);
				var lenN = Math.sqrt((_local3 * _local3) + (_local2 * _local2));
				var lenP = Math.sqrt((x * x) + (y * y));
				if (lenP < lenN)
				{
					obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, _local1);
					return(CollisionType.COL_AXIS);
				}
				else
				{
					obj.ReportCollisionVsWorld(_local3, _local2, _local1.signx, _local1.signy, _local1);
					return(CollisionType.COL_OTHER);
				}
			}
			return(CollisionType.COL_NONE);
			return(_local3);
		}

		private static function ProjAABB_Concave(x, y, obj, t):int
		{
			var _local1 = t;
			var signx = _local1.signx;
			var signy = _local1.signy;
			var ox = ((_local1.pos.x + (signx * _local1.xw)) - (obj.pos.x - (signx * obj.xw)));
			var _local3 = (_local1.pos.y + (signy * _local1.yw)) - (obj.pos.y - (signy * obj.yw));
			var twid = (_local1.xw * 2);
			var rad = Math.sqrt((twid * twid) + 0);
			var len = Math.sqrt((ox * ox) + (_local3 * _local3));
			var _local2 = len - rad;
			if (0 < _local2)
			{
				var lenP = Math.sqrt((x * x) + (y * y));
				if (lenP < _local2)
				{
					obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, _local1);
					return(CollisionType.COL_AXIS);
				}
				else
				{
					ox = ox / len;
					_local3 = _local3 / len;
					obj.ReportCollisionVsWorld(ox * _local2, _local3 * _local2, ox, _local3, _local1);
					return(CollisionType.COL_OTHER);
				}
			}
			return(CollisionType.COL_NONE);
			return(_local3);
		}

		private static function ProjAABB_Convex(x, y, obj, t):int
		{
			var _local1 = t;
			var signx = _local1.signx;
			var signy = _local1.signy;
			var _local3 = (obj.pos.x - (signx * obj.xw)) - (_local1.pos.x - (signx * _local1.xw));
			var _local2 = (obj.pos.y - (signy * obj.yw)) - (_local1.pos.y - (signy * _local1.yw));
			var len = Math.sqrt((_local3 * _local3) + (_local2 * _local2));
			var twid = (_local1.xw * 2);
			var rad = Math.sqrt((twid * twid) + 0);
			var pen = (rad - len);
			if (((signx * _local3) < 0) || ((signy * _local2) < 0))
			{
				var lenP = Math.sqrt((x * x) + (y * y));
				obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, _local1);
				return(CollisionType.COL_AXIS);
			}
			else if (0 < pen)
			{
				_local3 = _local3 / len;
				_local2 = _local2 / len;
				obj.ReportCollisionVsWorld(_local3 * pen, _local2 * pen, _local3, _local2, _local1);
				return(CollisionType.COL_OTHER);
			}
			return(CollisionType.COL_NONE);
			return(_local3);
		}

		private static function ProjAABB_45Deg(x, y, obj, t):int
		{
			var _local1 = t;
			var signx = _local1.signx;
			var signy = _local1.signy;
			var ox = ((obj.pos.x - (signx * obj.xw)) - _local1.pos.x);
			var oy = ((obj.pos.y - (signy * obj.yw)) - _local1.pos.y);
			var _local3 = _local1.sx;
			var _local2 = _local1.sy;
			var dp = ((ox * _local3) + (oy * _local2));
			if (dp < 0)
			{
				_local3 = _local3 * (-dp);
				_local2 = _local2 * (-dp);
				var lenN = Math.sqrt((_local3 * _local3) + (_local2 * _local2));
				var lenP = Math.sqrt((x * x) + (y * y));
				if (lenP < lenN)
				{
					obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, _local1);
					return(CollisionType.COL_AXIS);
				}
				else
				{
					obj.ReportCollisionVsWorld(_local3, _local2, _local1.sx, _local1.sy);
					return(CollisionType.COL_OTHER);
				}
			}
			return(CollisionType.COL_NONE);
			return(_local3);
		}

		private static function ProjAABB_22DegS(x, y, obj, t):int
		{
			var _local1 = t;
			var _local2 = obj;
			var signx = _local1.signx;
			var signy = _local1.signy;
			var py = (_local2.pos.y - (signy * _local2.yw));
			var _local3 = _local1.pos.y - py;
			if (0 < (_local3 * signy))
			{
				var ox = ((_local2.pos.x - (signx * _local2.xw)) - (_local1.pos.x + (signx * _local1.xw)));
				var oy = ((_local2.pos.y - (signy * _local2.yw)) - (_local1.pos.y - (signy * _local1.yw)));
				var sx = _local1.sx;
				var sy = _local1.sy;
				var dp = ((ox * sx) + (oy * sy));
				if (dp < 0)
				{
					sx = sx * (-dp);
					sy = sy * (-dp);
					var lenN = Math.sqrt((sx * sx) + (sy * sy));
					var lenP = Math.sqrt((x * x) + (y * y));
					var aY = Math.abs(_local3);
					if (lenP < lenN)
					{
						if (aY < lenP)
						{
							_local2.ReportCollisionVsWorld(0, _local3, 0, _local3 / aY, _local1);
							return(CollisionType.COL_OTHER);
						}
						_local2.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, _local1);
						return(CollisionType.COL_AXIS);
					}
					else if (aY < lenN)
					{
						_local2.ReportCollisionVsWorld(0, _local3, 0, _local3 / aY, _local1);
						return(CollisionType.COL_OTHER);
					}
					else
					{
						_local2.ReportCollisionVsWorld(sx, sy, _local1.sx, _local1.sy, _local1);
						return(CollisionType.COL_OTHER);
					}
				}
			}
			return(CollisionType.COL_NONE);
			return(_local3);
		}

		private static function ProjAABB_22DegB(x, y, obj, t):int
		{
			var _local1 = t;
			var signx = _local1.signx;
			var signy = _local1.signy;
			var ox = ((obj.pos.x - (signx * obj.xw)) - (_local1.pos.x - (signx * _local1.xw)));
			var oy = ((obj.pos.y - (signy * obj.yw)) - (_local1.pos.y + (signy * _local1.yw)));
			var _local3 = _local1.sx;
			var _local2 = _local1.sy;
			var dp = ((ox * _local3) + (oy * _local2));
			if (dp < 0)
			{
				_local3 = _local3 * (-dp);
				_local2 = _local2 * (-dp);
				var lenN = Math.sqrt((_local3 * _local3) + (_local2 * _local2));
				var lenP = Math.sqrt((x * x) + (y * y));
				if (lenP < lenN)
				{
					obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, _local1);
					return(CollisionType.COL_AXIS);
				}
				else
				{
					obj.ReportCollisionVsWorld(_local3, _local2, _local1.sx, _local1.sy, _local1);
					return(CollisionType.COL_OTHER);
				}
			}
			return(CollisionType.COL_NONE);
			return(_local3);
		}

		private static function ProjAABB_67DegS(x, y, obj, t):int
		{
			var _local1 = t;
			var _local2 = obj;
			var signx = _local1.signx;
			var signy = _local1.signy;
			var px = (_local2.pos.x - (signx * _local2.xw));
			var _local3 = _local1.pos.x - px;
			if (0 < (_local3 * signx))
			{
				var ox = ((_local2.pos.x - (signx * _local2.xw)) - (_local1.pos.x - (signx * _local1.xw)));
				var oy = ((_local2.pos.y - (signy * _local2.yw)) - (_local1.pos.y + (signy * _local1.yw)));
				var sx = _local1.sx;
				var sy = _local1.sy;
				var dp = ((ox * sx) + (oy * sy));
				if (dp < 0)
				{
					sx = sx * (-dp);
					sy = sy * (-dp);
					var lenN = Math.sqrt((sx * sx) + (sy * sy));
					var lenP = Math.sqrt((x * x) + (y * y));
					var aX = Math.abs(_local3);
					if (lenP < lenN)
					{
						if (aX < lenP)
						{
							_local2.ReportCollisionVsWorld(_local3, 0, _local3 / aX, 0, _local1);
							return(CollisionType.COL_OTHER);
						}
						_local2.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, _local1);
						return(CollisionType.COL_AXIS);
					}
					else if (aX < lenN)
					{
						_local2.ReportCollisionVsWorld(_local3, 0, _local3 / aX, 0, _local1);
						return(CollisionType.COL_OTHER);
					}
					else
					{
						_local2.ReportCollisionVsWorld(sx, sy, _local1.sx, _local1.sy, _local1);
						return(CollisionType.COL_OTHER);
					}
				}
			}
			return(CollisionType.COL_NONE);
			return(_local3);
		}

		private static function ProjAABB_67DegB(x, y, obj, t):int
		{
			var _local1 = t;
			var signx = _local1.signx;
			var signy = _local1.signy;
			var ox = ((obj.pos.x - (signx * obj.xw)) - (_local1.pos.x + (signx * _local1.xw)));
			var oy = ((obj.pos.y - (signy * obj.yw)) - (_local1.pos.y - (signy * _local1.yw)));
			var _local3 = _local1.sx;
			var _local2 = _local1.sy;
			var dp = ((ox * _local3) + (oy * _local2));
			if (dp < 0)
			{
				_local3 = _local3 * (-dp);
				_local2 = _local2 * (-dp);
				var lenN = Math.sqrt((_local3 * _local3) + (_local2 * _local2));
				var lenP = Math.sqrt((x * x) + (y * y));
				if (lenP < lenN)
				{
					obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, _local1);
					return(CollisionType.COL_AXIS);
				}
				else
				{
					obj.ReportCollisionVsWorld(_local3, _local2, _local1.sx, _local1.sy, _local1);
					return(CollisionType.COL_OTHER);
				}
			}
			return(CollisionType.COL_NONE);
			return(_local3);
		}
	}
}